package com.ctshk.rpc.starvip.util;

import javax.xml.bind.annotation.adapters.XmlAdapter;
import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.util.Optional;

/**
 * @BelongsProject: ctshk-cloud
 * @BelongsPackage: com.ctshk.rpc.starvip.util
 * @Author: hef
 * @CreateTime: 2021-04-13 10:08
 * @Description: 描述
 */
public class JAXBDateFromater extends XmlAdapter<String, LocalDate> {
    private static final String formater = "MM/dd/yyyy";

    @Override
    public LocalDate unmarshal(String v) throws Exception {
        Optional<String> optional = Optional.ofNullable(v);
        if (optional.isPresent()) {
            return null;
        }
        LocalDate localDate = LocalDate.parse(v, DateTimeFormatter.ofPattern(formater));
        return localDate;
    }

    @Override
    public String marshal(LocalDate v) throws Exception {
        String format = v.format(DateTimeFormatter.ofPattern(formater));
        return format;
    }
}
